using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Facebook.Entity;
using System.Collections.ObjectModel;

public partial class _controls_FriendsWorkItems : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            FriendDropDownListBind();
    }

    protected void drpFriends_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpFriends.SelectedValue == "0")
        {
            this.lblTitle.Visible = false;
            this.ucList.Clear();
            return;
        }

        this.lblTitle.Visible = true;

        User user = IMadeThisService.Current.GetFriend(this.drpFriends.SelectedValue);

        this.ucList.UserID = this.drpFriends.SelectedValue;
        this.lblWorkItemsCount.Text = string.Format("{0} Work Item(s)", this.ucList.ItemsCount);

        this.lblTitle.Text = string.Format("{0} made ...", user.FirstName);
        this.imgPhoto.ImageUrl = user.PictureSquareUrl.ToString();

        if (user.PictureSmallUrl.ToString().Contains("s_default.jpg"))
            this.imgPhoto.Width = this.imgPhoto.Height = 50;
            
    }

    private void FriendDropDownListBind()
    {
        Collection<User> _friends = IMadeThisService.Current.Friends;

        if (_friends.Count == 0)
        {
            this.pnlContents.Visible = false;
            this.pnlWarningNoFriendsAddedApp.Visible = true;
            return;
        }

        this.drpFriends.DataSource = _friends;
        this.drpFriends.DataTextField = "Name";
        this.drpFriends.DataValueField = "UserID";
        this.drpFriends.DataBind();
        
        this.drpFriends.Items.Insert(0, new ListItem("Select Friend", "0"));
        this.lblTitle.Visible = false;
    }
}
